﻿package com.mui.utils
{
    import flash.events.*;
    import flash.utils.*;

    public class ObjEventListerTool extends Object
    {
        private static var dicObjEvents:Dictionary = new Dictionary(true);

        public function ObjEventListerTool()
        {
            return;
        }// end function

        public static function addObjEvent(param1:IEventDispatcher, param2:String, param3:Function, param4:Boolean) : void
        {
            var _loc_6:LisObj = null;
            if (!hasObjEvent(param1))
            {
                dicObjEvents[param1] = [];
            }
            var _loc_5:* = dicObjEvents[param1];
            for each (_loc_6 in _loc_5)
            {
                
                if (_loc_6.type == param2 && _loc_6.listener == param3 && _loc_6.useCapture == param4)
                {
                    return;
                }
            }
            _loc_6 = new LisObj(param2, param3, param4);
            _loc_5.push(_loc_6);
            return;
        }// end function

        public static function hasObjEvent(param1:IEventDispatcher) : Boolean
        {
            return dicObjEvents[param1] != null && dicObjEvents[param1] != undefined;
        }// end function

        public static function removeObjEvent(param1:IEventDispatcher, param2:String, param3:Function, param4:Boolean) : void
        {
            var _loc_5:Array = null;
            var _loc_6:int = 0;
            var _loc_7:LisObj = null;
            var _loc_8:int = 0;
            if (hasObjEvent(param1))
            {
                _loc_5 = dicObjEvents[param1];
                _loc_6 = _loc_5.length;
                _loc_8 = _loc_6 - 1;
                while (_loc_8 >= 0)
                {
                    
                    _loc_7 = _loc_5[_loc_8] as LisObj;
                    if (_loc_7.type == param2 && _loc_7.listener == param3 && _loc_7.useCapture == param4)
                    {
                        _loc_5.splice(_loc_8, 1);
                    }
                    _loc_8 = _loc_8 - 1;
                }
                if (_loc_5.length == 0)
                {
                    delete dicObjEvents[param1];
                }
            }
            return;
        }// end function

        public static function delObjEvent(param1:IEventDispatcher) : void
        {
            var _loc_2:Array = null;
            var _loc_3:LisObj = null;
            var _loc_4:int = 0;
            if (hasObjEvent(param1))
            {
                _loc_2 = dicObjEvents[param1];
                _loc_4 = _loc_2.length - 1;
                while (_loc_4 >= 0)
                {
                    
                    _loc_3 = _loc_2[_loc_4];
                    param1.removeEventListener(_loc_3.type, _loc_3.listener, _loc_3.useCapture);
                    _loc_4 = _loc_4 - 1;
                }
                delete dicObjEvents[param1];
            }
            return;
        }// end function

    }
}

class LisObj extends Object
{
    public var type:String;
    public var listener:Function;
    public var useCapture:Boolean;

    function LisObj(param1:String, param2:Function, param3:Boolean)
    {
        this.type = param1;
        this.listener = param2;
        this.useCapture = param3;
        return;
    }// end function

}

